unit ProcuraCliente;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Padrao, FMTBcd, StdCtrls, ExtCtrls, DB, DBClient, Provider, SqlExpr,
  Grids, DBGrids, ImgList, ComCtrls, ToolWin;

type
  TFormProcuraCliente = class(TFormPadrao)
    DBGrid1: TDBGrid;
    Panel1: TPanel;
    SQLQueryProcuraCliente: TSQLQuery;
    DataSource1: TDataSource;
    DataSetProvider1: TDataSetProvider;
    ClientDataSet1: TClientDataSet;
    Label1: TLabel;
    EditProcura: TEdit;
    RadioGroup1: TRadioGroup;
    ClientDataSet1id: TIntegerField;
    ClientDataSet1nome: TStringField;
    ClientDataSet1telefone: TStringField;
    ClientDataSet1celular: TStringField;
    ClientDataSet1email: TStringField;
    procedure FormShow(Sender: TObject);
    procedure ToolButton5Click(Sender: TObject);
    procedure ProcuraTexto;
    procedure EditProcuraKeyUp(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure ToolButton2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    vIdcliente:integer;
  end;

var
  FormProcuraCliente: TFormProcuraCliente;
  vSql:string;

implementation
uses login;

{$R *.dfm}

procedure TFormProcuraCliente.EditProcuraKeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  inherited;
  ProcuraTexto;
end;

procedure TFormProcuraCliente.FormShow(Sender: TObject);
begin
  inherited;
  vSql := 'select * from cliente order by nome ';

  SQLQueryProcuraCliente.SQL.Clear;
  SQLQueryProcuraCliente.SQL.Add(vSql);
  SQLQueryProcuraCliente.Close;
  SQLQueryProcuraCliente.Open;

  ClientDataSet1.Close;
  ClientDataSet1.Open;
end;

procedure TFormProcuraCliente.ToolButton2Click(Sender: TObject);
begin
  inherited;

  vIdcliente := ClientDataSet1.FieldByName('id').AsInteger;
  close;
end;

procedure TFormProcuraCliente.ToolButton5Click(Sender: TObject);
begin
  inherited;
  SELF.Close;
end;

procedure TFormProcuraCliente.ProcuraTexto;
var xprocura:string;
begin
  if ( RadioGroup1.ItemIndex = 0 ) then
     xprocura := ' nome '
  else if ( RadioGroup1.ItemIndex = 1 ) then
     xprocura := 'telefone '
  else if ( RadioGroup1.ItemIndex = 2 ) then
     xprocura := 'celular ';

  xprocura := xprocura + 'like ''%'+EditProcura.Text+'%''';


  vSql := 'select * from cliente where '+ xprocura + ' order by nome';

  SQLQueryProcuraCliente.SQL.Clear;
  SQLQueryProcuraCliente.SQL.Add(vSql);
  SQLQueryProcuraCliente.Close;
  SQLQueryProcuraCliente.Open;

  ClientDataSet1.Close;
  ClientDataSet1.Open;
end;

end.
